/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author menandro.neto
 */
public class Cadastro extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            
            String nome = request.getParameter("nome");
            String sobreNome = request.getParameter("sobrenome");
            String [] preferencia = request.getParameterValues("preferencia");
            String operadora = request.getParameter("operadora");
            String banda = request.getParameter("banda");
            
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Cadastro</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet - " + this.toString() + " at " + request.getContextPath () + "</h1>");
            
            out.println("<table> <caption> </caption>");
            out.println("<theader> </theader>");
            out.println("<tfoot> </tfoot>");
            
            out.println("<tbody> ");
            out.printf("<tr> <td> Nome: </td> <td> %s </td></tr> ", nome);
            out.printf("<tr> <td> Sobrenome: </td> <td> %s </td></tr> ", sobreNome);
            out.printf("<tr> <td> Operadora: </td> <td> %s </td></tr> ", operadora.toUpperCase());
            out.printf("<tr> <td> Banda: </td> <td> %s </td></tr> ", banda);
            
            for (String tmp: preferencia)
                out.printf("<tr> <td> Preferência: </td> <td> %s </td></tr> ", tmp);
            
            out.println("</tbody> </table>");
            out.println("</body>");
            out.println("</html>");
            
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="Métodos HttpServlet. Clique no sinal de + à esquerda para editar o código.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
